const Router = require('koa-router')

//导入中间件
const { auth, hadAdminPermission } = require('../middleware/auth.middleware')

//导入课程验证相关的中间件
const {
  validator,
  saveCourseInfoValitator
} = require('../middleware/courses.middleware')

//导入上传相关的控制器
const { upload, aliUpload } = require('../controller/upload.controller')

const {
  create,
  saveCourseInfo,
  getCourseList,
  getCourseInfoById,
  getAllChapter,
  getChAndLeByCourseId,
  getChapterById,
  saveOrUpdateChapter,
  test
} = require('../controller/course.controller')

const router = new Router({ prefix: '/course' })

//课程图片上传接口
router.post('/upload', auth, hadAdminPermission, upload)
//router.post('/upload', upload)

//阿里云上传接口
router.post('/aliUpload', auth, hadAdminPermission, aliUpload)

//阿里云上传接口,测试
router.post('/aliUploadtest', aliUpload)

//发布商品接口
router.post('/', auth, hadAdminPermission, validator, create)

//保存课程信息接口
//router.post('/saveCourseInfo',saveCourseInfoValitator, saveCourseInfo)
router.post('/saveCourseInfo', saveCourseInfo)

//获取课程列表接口
router.get('/getCourseList', getCourseList)

//通过ID获取单门课程信息
router.get('/getCourseInfoById', getCourseInfoById)

//获取所有章节信息
router.get('/getAllChapter', getAllChapter)

//获取课程下所有章节和课时信息
router.get('/getChAndLeByCourseId', getChAndLeByCourseId)

//通过ID获取章节信息
router.get('/getChapterById', getChapterById)

//新建或更新章节信息
router.post('/saveOrUpdateChapter', saveOrUpdateChapter)

//测试
router.get('/test', test)

module.exports = router
